~ chicken-core (master) /manual/Module (chicken io)
Trap1[[tags: manual]]2[[toc:]]34== Module (chicken io)56This module provides various Input/Output extensions.78=== read-list910<procedure>(read-list [PORT [READER [MAX]]])</procedure>1112Call {{READER}} up to {{MAX}} times and collect its output in a list. If {{MAX}} is {{#f}}, read until end of file.1314The reader is called with one argument: {{PORT}}.1516{{READER}} defaults to {{read}}, {{MAX}} to {{#f}} and {{PORT}} to {{current-input-port}}, so if you call it with no arguments, it will read all remaining s-expressions from the current input port.171819=== read-byte20=== write-byte2122<procedure>(read-byte [PORT])</procedure><br>23<procedure>(write-byte BYTE [PORT])</procedure>2425Read/write a byte to the port given in {{PORT}}, which default to the values26of {{(current-input-port)}} and {{(current-output-port)}}, respectively.272829=== read-line30=== write-line3132<procedure>(read-line [PORT [LIMIT]])</procedure><br>33<procedure>(write-line STRING [PORT])</procedure>3435Line-input and -output. {{PORT}} defaults to the value of36{{(current-input-port)}} and {{(current-output-port)}},37respectively. If the optional argument {{LIMIT}} is given and38not {{#f}}, then {{read-line}} reads at most {{LIMIT}}39characters per line. {{read-line}} returns a string without the terminating newline and {{write-line}} adds a terminating newline before outputting.404142=== read-lines4344<procedure>(read-lines [PORT [MAX]])</procedure>4546Read {{MAX}} or fewer lines from {{PORT}}. {{MAX}} defaults to47{{most-positive-fixnum}} and {{PORT}} defaults to the value of48{{(current-input-port)}}. Returns a list of strings, each string49representing a line read, not including any line separation50character(s).515253=== read-string54=== read-string!5556<procedure>(read-string [NUM [PORT]])</procedure><br>57<procedure>(read-string! NUM STRING [PORT [START]])</procedure><br>5859Read or write {{NUM}} characters from/to {{PORT}}, which defaults to the60value of {{(current-input-port)}} or {{(current-output-port)}}, respectively.6162If {{NUM}} is {{#f}} or not given, then all data up to the end-of-file is63read, or, in the case of {{write-string}} the whole string is written. If no64more input is available, {{read-string}} returns {{#!eof}}.6566{{read-string!}} reads destructively into the given {{STRING}} argument, but67never more characters than would fit into {{STRING}}. If {{START}} is given,68then the read characters are stored starting at that position.69{{read-string!}} returns the actual number of characters read.707172=== read-bytevector7374<procedure>(read-bytevector [NUM [PORT]])</procedure>7576Read {{NUM}} bytes from {{PORT}}, which defaults to the77value of {{(current-input-port)}}. {{read-bytevector}} allocates78a new buffer and returns it (or the end-of-file object, if at the end79of the input file).8081If {{NUM}} is optional and not given, then all remaining input is read82or the whole bytevector is read/written.8384=== read-bytevector!8586<procedure>(read-bytevector! BYTEVECTOR [PORT START END])</procedure>8788Read bytes from {{PORT}} into {{BYTEVECTOR}}. {{PORT}} defaults to the89value of {{(current-input-port)}} and returns the actual number of bytes read.9091{{START}} and {{END}} designate the range of bytes that should be filled92with input from {{PORT}}. If {{END}} exceeeds the length of {{BYTEVECTOR}}93only as much data is read as fits into the destination buffer.9495=== write-bytevector9697<procedure>(write-bytevector BYTEVECTOR [PORT START END])</procedure>9899Write bytes from {{BYTEVECTOR}} to {{PORT}}. {{PORT}} defaults to the100value of {{(current-output-port)}}.101102{{START}} and {{END}} designate the range of bytes that should be written.103If {{END}} exceeeds the length of {{BYTEVECTOR}}104only as much data is written as is available.105106107=== read-token108109<procedure>(read-token PREDICATE [PORT])</procedure>110111Reads characters from {{PORT}} (which defaults to the value of {{(current-input-port)}})112and calls the procedure {{PREDICATE}} with each character until {{PREDICATE}} returns113false. Returns a string with the accumulated characters.114115---116Previous: [[Module (chicken gc)]]117118Next: [[Module (chicken irregex)]]